﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;

namespace AlbumArtOrganizer.Plugins.Google.Model
{
    [Export(AlbumArtOrganizer.Plugins.Google.ImageFinder.ImageFinder.OPTIONCONTRACTNAME, typeof(AlbumArtOrganizer.Model.IOption))]
    public class OptionImageSize : AlbumArtOrganizer.Model.OptionEnumeration
    {
        public enum Type
        {
            Small,
            Medium,
            Large,
            Huge
        }

        public override string Title
        {
            get
            {
                return "Image size";
            }
        }

        public override string Description
        {
            get
            {
                return "Size filter for images returned.";
            }
        }

        public override IEnumerable<string> AllowedValues
        {
            get
            {
                return from OptionImageSize.Type item in Enum.GetValues(typeof(OptionImageSize.Type))
                       select item.ToString();
            }
        }

        string _value = null;
        public override string Value
        {
            get
            {
                if (String.IsNullOrEmpty(_value))
                {
                    _value = Properties.Settings.Default.OptionImageSize;
                }
                return _value;
            }
            set
            {
                _value = value;
                Properties.Settings.Default.OptionImageSize = value;
                Properties.Settings.Default.Save();
            }
        }

        public string GetSearchValue()
        {
            var option = (from OptionImageSize.Type item in Enum.GetValues(typeof(OptionImageSize.Type))
                          where item.ToString() == Value
                          select item).First();
            return option.ToSearchString();
        }
    }

    public static class OptionImageSizeExtensions
    {
        public static string ToSearchString(this OptionImageSize.Type option)
        {
            switch (option)
            {
                case OptionImageSize.Type.Small:
                    return "icon";
                case OptionImageSize.Type.Medium:
                    return "medium";
                case OptionImageSize.Type.Large:
                    return "xxlarge";
                case OptionImageSize.Type.Huge:
                    return "huge";
            }
            throw new InvalidOperationException();
        }
    }
}
